package com.zmytest.one2many;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created on 2018/12/24.
 *
 * @author zhangmingyu
 */
@RestController
@RequestMapping("/one2many")
public class Test2Controller {

    @Autowired
    private CarRepository carRepository;
    @Autowired
    private OwnerRepository ownerRepository;

    @GetMapping("/create")
    public void test(){

        Owner owner = new Owner();
        owner.setName("zmytest");
        Owner o = ownerRepository.save(owner);
        Car car = new Car();
        car.setModel("porsche");
        car.setOwnerId(o.getId());
        Car result = carRepository.save(car);

        System.out.println("result "+result);
    }
}
